package chapter7.section4;

//程序7-8：改写的main方法，使用try-catch机制捕获异常
public class Summer {
	public static int summer(int[] score) {
		int amount = 0;
		for (int i = 0; i < score.length; i++) {// 这一行可能会抛出异常对象
			amount += score[i];
		}
		return amount;
	}

	public static void main(String[] args) {
		int[] score = null;
		try {
			int result = summer(score);
		} catch (NullPointerException e) {
			System.out.println("调用summer发生错误，原因：" + e.getMessage());
		}
	}

}